﻿using AutoMapper;
using MediatR;
using T_vehicle.API.Application.Command.AccidentCommand;
using T_vehicle.Domain;
using T_vehicle.Infrastructure.Interfacec;

namespace T_vehicle.API.Application.CommandHandlers.AccidentCommandHandlers
{
    public class UpdateAccidentCommandHandlers:IRequestHandler<UpdateAccidentCommand,int>
    {
        private readonly IAccidentRepository accidentRepository;
        private readonly IMapper mapper;

        public UpdateAccidentCommandHandlers(IAccidentRepository accidentRepository, IMapper mapper)
        {
            this.accidentRepository = accidentRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(UpdateAccidentCommand request, CancellationToken cancellationToken)
        {

            var Info = mapper.Map<Accident>(request);
            Info.CreateDate = DateTime.Now;
            return await accidentRepository.UpdateAsync(Info);
            //var Info = new Accident();
            //Info.AccidentTitle = request.AccidentTitle;
            //Info.LicenNumber = request.LicenNumber;
            //Info.Incident = request.Incident;
            //Info.IncidentDate = request.IncidentDate;
            //Info.Indemnify = request.Indemnify;
            //Info.loss = request.loss;
            //Info.Description = request.Description;
            //Info.Remark = request.Remark;
            //Info.Netloss = request.Netloss;
            //Info.CreateDate = DateTime.Now;
            //Info.AccidentId = request.AccidentId;   
            //return await accidentRepository.UpdateAsync(Info);
        }
    }
}
